package com.szp.lagou.dubbo.filerDemo.consumer.controller;

import com.szp.lagou.dubbo.filerDemo.filter.TransportIPFilter;
import com.szp.lagou.dubbo.filerDemo.provider.service.DemoService;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.stereotype.Component;

import java.util.concurrent.*;

@Component
public class HelloController {
    @Reference
    DemoService demoService;

    public void hello(String name) {
        ThreadPoolExecutor threadPool = new ThreadPoolExecutor(3, 10,
                100, TimeUnit.MICROSECONDS, new LinkedBlockingQueue<Runnable>());
//        String clientIp = request.getRemoteAddr();
//        IpContext.getContext().setClientIp(clientIp);
//        String name = "jack";
        TransportIPFilter transportIPFilter = new TransportIPFilter();
        Thread thread = new Thread(transportIPFilter);
        thread.start();
        while(true){
            Future<String> futureA = threadPool.submit(()-> demoService.methodA(name));
            Future<String> futureB = threadPool.submit(()-> demoService.methodB(name));
            Future<String> futureC = threadPool.submit(()-> demoService.methodC(name));
//            try {
//                System.out.println(futureA.get());
//                System.out.println(futureB.get());
//                System.out.println(futureC.get());
//                System.out.println("++++++++++++++++++++");
//            } catch (InterruptedException e) {
//                e.printStackTrace();
//            } catch (ExecutionException e) {
//                e.printStackTrace();
//            }
//            System.out.println("++++++++++++++++++++");
        }
    }
}
